<script setup lang="ts">
import { OrderType } from "@/enums";
import { getMedicineOrderDetailApi } from "@/services/consult";
import type { OrderDetail } from "@/types/order";
import { ref, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const route = useRoute();
const Medicine = ref<OrderDetail>();
onMounted(async () => {
  const res = await getMedicineOrderDetailApi(route.query.orderId as string);
  Medicine.value = res.data;
});
</script>

<template>
  <div class="orderDetail-page" v-if="Medicine">
    <cp-nav-bar title="药品订单详情"></cp-nav-bar>
    <div class="bg"></div>
    <div class="address-box">
      <div class="address" @click="router.push('/orderMap/' + Medicine.id)">
        <div class="left">
          <p>{{ Medicine?.expressInfo?.content || "" }}</p>
          <p>{{ Medicine?.expressInfo?.time || "" }}</p>
        </div>
        <van-icon name="arrow"></van-icon>
      </div>
    </div>
    <div class="yaofang">
      <div class="top">
        <p>优医药房 <span>优医质保 假一赔十</span></p>
      </div>
      <div class="list">
        <div class="item" v-for="item in Medicine?.medicines" :key="item.id">
          <div class="order">
            <img :src="item.avatar" alt="" />
            <div class="txt">
              <p>{{ item.name }}</p>
              <p>
                <span>{{
                  item.prescriptionFlag === 1 ? "处方药" : "非处方药"
                }}</span>
                <span>{{ item.specs }}</span>
              </p>
              <p>￥{{ item.amount }}</p>
            </div>
            <p>x{{ item.quantity }}</p>
          </div>
          <div class="content">
            <p>{{ item.usageDosag }}</p>
          </div>
        </div>
      </div>
      <van-cell
        border
        title="药品金额"
        :value="`￥${Medicine?.actualPayment}`"
        size="large"
      />
      <van-cell
        border
        title="运费"
        :value="`￥${Medicine?.expressFee}`"
        size="large"
      />
      <van-cell
        border
        title="优惠券"
        :value="`-￥${Medicine?.couponDeduction}`"
        size="large"
      />
      <van-cell
        class="text"
        border
        title="实付款"
        :value="`￥${Medicine?.actualPayment}`"
        size="large"
      />
      <van-cell
        class="orderNo"
        border
        title="订单编号"
        :value="`${Medicine?.orderNo}`"
        size="large"
      />
      <van-cell
        border
        title="创建时间"
        :value="`${Medicine?.createTime}`"
        size="large"
      />
      <van-cell
        border
        title="支付时间"
        :value="`${Medicine?.payTime}`"
        size="large"
      />
      <van-cell
        style="padding-bottom: 100px"
        border
        title="支付方式"
        :value="`${Medicine?.paymentMethod === 0 ? '微信' : '支付宝'}`"
        size="large"
      />
    </div>
    <div class="btn">
      <van-button type="primary" block round>确认收货</van-button>
    </div>
  </div>
  <!-- <van-skeleton title :row="3" v-else /> -->
</template>

<style lang="scss" scoped>
.orderDetail-page {
  height: 100vh;
  .bg {
    height: 70px;
    background: linear-gradient(to bottom, #f5f8f8, #e1f1ef);
    border-bottom-left-radius: 35px;
    border-bottom-right-radius: 35px;
    position: relative;
    margin-bottom: 40px;
  }
  .address-box {
    width: 100%;
    height: 80px;
    position: absolute;
    top: 58px;
    left: 0;

    .address {
      background-color: #fff;
      width: 95%;
      height: 100%;
      margin: 0 auto;
      box-shadow: 0 0 3px #cccccc6b;
      border-radius: 10px;
      padding: 10px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .left {
        p:nth-child(1) {
          color: var(--cp-primary);
          margin-bottom: 5px;
        }
        p:nth-child(2) {
          color: var(--cp-text3);
        }
      }
    }
  }
  .yaofang {
    background-color: #fff;
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    .top {
      height: 30px;
      line-height: 30px;
      border-bottom: 1px solid #f0f0f0;
      margin-bottom: 10px;
      p {
        font-size: 16px;
        span {
          color: var(--cp-text3);
          font-size: 14px;
        }
      }
    }
    .list {
      .item:last-child {
        padding-bottom: 10px;
        border-bottom: 1px solid #f0f0f0;
      }
      .item {
        margin: 10px 0;

        .content {
          background-color: #f6f7f9;
          padding: 10px;
        }
        .order {
          display: flex;
          padding-bottom: 10px;
          img {
            width: 100px;
            height: 100px;
          }

          .txt {
            flex: 1;
            p:nth-child(2) {
              margin: 5px 0;
              span:nth-child(1) {
                color: #fff;
                background-color: var(--cp-primary);
                padding: 1px 4px;
                margin-right: 5px;
              }
            }
          }
        }
      }
    }
    :deep() {
      .text {
        .van-cell__value {
          color: red;
          font-size: 18px;
        }
      }
      .orderNo {
        white-space: nowrap;
      }
    }
  }
}
.btn {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 60px;
  line-height: 60px;
  background-color: #fff;
  .van-button {
    width: 98%;
    margin: auto;
  }
}
</style>
